import { useUserStore } from '@/stores/UserStore'
import axios from 'axios'
import { ElMessage, type MessageType } from 'element-plus'
const instance = axios.create({
  baseURL: import.meta.env.VITE_BASE_URL,
  timeout: 3000,
})
// axios拦截器
// 请求拦截器
instance.interceptors.request.use(
  (config) => {
    //   const store=useUserStore();
    //   if(store.token){
    //     config.headers.token=store.token;
    //   }
    return config
  },
  (error) => {
    return Promise.reject(error)
  },
)
// 响应拦截器
instance.interceptors.response.use(
  (response) => {
    // if(response.data.type!=="upload")  ElMessage({
    //     message:response.data.msg,
    //     type:["info","success","warning"][~~(response.status/100)-1] as MessageType
    //   })
    return response
  },
  (error) => {
    //   ElMessage({
    //     message:error.message,
    //     type:"error"
    //   })
    return Promise.reject(error)
  },
)

export default instance
